﻿using System;
using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The birth report object.
    /// </summary>
    public partial class BirthReport
    {
        /// <summary>
        /// Holds the <see cref="BirthReportRepository"/> instance.
        /// </summary>
        static BirthReportRepository repository = new BirthReportRepository();

        /// <summary>
        /// Finds the <see cref="BirthReport"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="BirthReport"/>.</param>
        /// <returns>Found <see cref="BirthReport"/> object, null if not found.</returns>
        public static BirthReport FindById(int id)
        {
            return repository.FindBy(birthReport => birthReport.BirthReportId == id);
        }

        /// <summary>
        /// Finds the <see cref="BirthReport"/> by provided conditions.
        /// </summary>
        /// <param name="verififcationCode">The verification code.</param>
        /// <param name="associatedParentId">The associated parent id.</param>
        /// <returns>Found <see cref="BirthReport"/> object, null if not found.</returns>
        public static BirthReport FindByVerificationCode(string verififcationCode, int associatedParentId)
        {
            return repository.FindBy(birthReport => birthReport.VerificationCode == verififcationCode && birthReport.AssociatedParent.UserId == associatedParentId);
        }

        /// <summary>
        /// Finds all <see cref="BirthReport"/>s.
        /// </summary>
        /// <returns>Found <see cref="BirthReport"/> objects, empty if none are found.</returns>
        public static List<BirthReport> FindAll()
        {
            return FindAll(true);
        }

        /// <summary>
        /// Finds all <see cref="BirthReport"/>s.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Found <see cref="BirthReport"/> objects, empty if none are found.</returns>
        public static List<BirthReport> FindAll(Func<BirthReport, bool> predicate)
        {
            return repository.FindAll(predicate);
        }

        /// <summary>
        /// Finds all <see cref="BirthReport"/>s.
        /// </summary>
        /// <param name="includeDeactivated">Whether to include deactivated.</param>
        /// <returns>Found <see cref="BirthReport"/> objects, empty if none are found.</returns>
        public static List<BirthReport> FindAll(bool includeDeactivated)
        {
            if (includeDeactivated)
            {
                return repository.FindAll();
            }
            else
            {
                return repository.FindAll(birthReport => birthReport.DeactivateReason == null);
            }
        }

        /// <summary>
        /// Retrives deactivated records.
        /// </summary>
        /// <returns>Found <see cref="BirthReport"/> objects, empty if none are found.</returns>
        public static List<BirthReport> GetDeactiveRecords()
        {
            return repository.FindAll(birthReport => birthReport.DeactivateReason != null);
        }

        /// <summary>
        /// To insert the <see cref="BirthReport"/>.
        /// </summary>
        /// <param name="birthReport">The <see cref="BirthReport"/> to insert.</param>
        /// <returns>The inserted <see cref="BirthReport"/> object.</returns>
        internal static BirthReport Insert(BirthReport birthReport)
        {
            return repository.Insert(birthReport);
        }

        /// <summary>
        /// To save the changes made to this object.
        /// </summary>
        /// <returns>Saved <see cref="BirthReport"/> object.</returns>
        internal BirthReport SaveChanges()
        {
            return repository.Update(this);
        }
    }
}
